package com.nan.controller.base;

import com.jfinal.core.Controller;
import com.jfinal.json.FastJson;
import com.nan.common.menu.Menu;
import com.nan.model.UserInfo;

public class BaseController extends Controller {
	
	public BaseController() {
		super();
	}
	
	public void show(String view) {
		_setAttr();
		render(view);
	}
	
	public void showJson(Object obj) {
		renderJson(getJson(obj));
	}
	
	public String getJson(Object o) {
		return FastJson.getJson().toJson(o);
	}
	
	private void _setAttr() {
		setAttr("BasePath", "/");
		setAttr("_menu", Menu.getMenu());
		
		UserInfo user = getSessionAttr("mm_login_user");
		setAttr("is_login", 0);
		setAttr("is_admin", 0);
		if (user != null)
		{
			setAttr("is_login", 1);
			if (user.getType() == 1)
			{
				setAttr("is_admin", 1);
			}
			setAttr("login_user", user);
		}
	}

}
